<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input size="small" style="width:200px;" v-model.trim="filters.serviceCname" placeholder="服务名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-select size="small" clearable v-model="filters.isValidate" style="width:200px;" placeholder="是否有效">
            <!-- <el-option label="全部状态" value="-1"></el-option> -->
            <el-option label="是" value="1"></el-option>
            <el-option label="否" value="0"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-col :xs="8" :sm="6" :md="4" :lg="4"> -->
        <el-form-item>
          <el-select size="small" clearable style="width:200px;" v-model="filters.serviceType" placeholder="服务类型">
            <!-- <el-option label="全部服务类型" value="-1"></el-option> -->
            <el-option label="理赔服务" value="理赔服务"></el-option>
            <el-option label="尊客会" value="尊客会"></el-option>
            <el-option label="在线客服" value="在线客服"></el-option>
            <el-option label="base" value="base"></el-option>
            <el-option label="店铺管理" value="店铺管理"></el-option>
            <el-option label="销售工具" value="销售工具"></el-option>
            <!-- <el-option label="更多" value="更多"></el-option> -->
          </el-select>
        </el-form-item>
        <!-- </el-col> -->
        <!-- <el-col :xs="8" :sm="6" :md="4" :lg="4"> -->
        <el-form-item>
          <el-select size="small" clearable style="width:200px;" v-model="filters.toType" placeholder="跳转类型">
            <!-- <el-option label="全部跳转类型" value="-1"></el-option> -->
            <el-option label="内部跳转" value="0"></el-option>
            <el-option label="外部跳转" value="1"></el-option>
            <el-option label="电话号码" value="2"></el-option>
            <el-option label="产品跳转" value="4"></el-option>
          </el-select>
        </el-form-item>
        <!-- </el-col> -->
        <!--  -->
        <el-form-item style="float:right;">
          <el-button size="small" class="button_style" type="primary" icon="upload2" @click="exportExcels" v-show="exportBtnVisible">导出</el-button>
        </el-form-item>
        <!--  -->
        <el-form-item style="float:right;">
          <el-button size="small" class="button_style" type="primary" icon="plus" @click="handleAdd" v-show="addBtnVisible">新增</el-button>
        </el-form-item>
        <!-- -->
        <el-form-item style="float:right;">
          <el-button size="small" v-show="queryBtnVisible" class="button_style" type="primary" icon="search" v-on:click="getServices(true)">查询</el-button>
        </el-form-item>

      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="Services" stripe border :height="winHeight-192" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column prop="serviceCname" label="服务名称" width="120" sortable>
      </el-table-column>
      <el-table-column prop="isValidate" label="是否有效" width="100" :formatter="formatisValidate">
      </el-table-column>
      <el-table-column prop="isFirst" label="是否首页" width="100" :formatter="formatisFirst">
      </el-table-column>
      <el-table-column prop="toType" label="跳转方式" width="100" :formatter="formattoType">
      </el-table-column>
      <el-table-column prop="serviceType" label="服务类型" width="100">
      </el-table-column>
      <el-table-column prop="serviceCode" label="服务编码" width="100" :formatter="formatisService">
      </el-table-column>
      <el-table-column prop="serviceEname" label="英文名称">
      </el-table-column>
      <el-table-column label="操作" fixed='right' width="150">
        <template scope="scope">
          <!--  -->
          <el-button size="small" type="warning" v-show="updateBtnVisible" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
          <!--  -->
          <el-button type="danger" v-show="deleteBtnVisible" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-button v-show="batchDeleteBtnVisible" type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>

      <el-pagination style="float:right" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page" :page-sizes="[10, 20, 40, 80]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-col>

    <!--修改界面-->
    <el-dialog title="修改" v-model="editFormVisible" :close-on-click-modal="false">
      <el-form :model="editForm" label-width="120px" :rules="editFormRules" ref="editForm">
        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="中文名称:" prop="serviceCname">
              <el-input v-model="editForm.serviceCname" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="英文名称:" prop="name">
              <el-input v-model="editForm.serviceEname" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="是否有效:" prop="isValidate">
              <el-select v-model="editForm.isValidate" class="otherWidth" placeholder="是否有效">
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="是否首页:" prop="isFirst">
              <el-select v-model="editForm.isFirst" class="otherWidth" placeholder="是否首页">
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="跳转方式:" prop="toType">
              <el-select v-model="editForm.toType" class="otherWidth" placeholder="跳转方式">
                <el-option label="内部跳转" value="0"></el-option>
                <el-option label="外部跳转" value="1"></el-option>
                <el-option label="电话号码" value="2"></el-option>
                <el-option label="产品跳转" value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="服务类型:" prop="serviceType">
              <el-select v-model="editForm.serviceType" class="otherWidth" placeholder="服务类型">
                <el-option label="理赔服务" value="理赔服务"></el-option>
                <el-option label="尊客会" value="尊客会"></el-option>
                <el-option label="在线客服" value="在线客服"></el-option>
                <el-option label="base" value="base"></el-option>
                <el-option label="店铺管理" value="店铺管理"></el-option>
                <el-option label="销售工具" value="销售工具"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="基本服务:" prop="baseService">
              <el-select v-model="editForm.baseService" class="otherWidth" placeholder="基本服务类型">
                <el-option label="保单查询" value="policy"></el-option>
                <el-option label="电子发票" value="invoice"></el-option>
                <el-option label="马上报案" value="fnol"></el-option>
                <el-option label="理赔查询" value="claim_query"></el-option>
                <el-option label="上传照片" value="claim_upload"></el-option>
                <el-option label="历史赔案" value="claim_history"></el-option>
                <el-option label="投保缴费" value="pay"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="序号:" prop="serialNo">
              <el-input v-model="editForm.serialNo" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-form :model="editForm" label-width="120px" :rules="editFormRules" ref="editForm">
        <el-form-item label="图片地址" prop="name">
          <!--  <el-input v-model="editForm.introduceUrl"  auto-complete="off"></el-input> -->
          <el-upload class="upload-demo" :action="picURL" :on-success="editSuccessUrl" :on-remove="editRemoveUrl" :file-list="fileList2" :data="{parampath:'servicemenu'}" list-type="picture">
            <el-button size="small" type="primary">点击上传</el-button>
            <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
          </el-upload>
        </el-form-item>
        <!-- <el-form-item label="服务编码:" prop="serviceCode">
                    <el-input v-model="editForm.serviceCode" auto-complete="off"></el-input>
                </el-form-item> -->
        <el-form-item label="服务编码:" prop="serviceCode">
          <el-select v-model="editForm.serviceCode" style="width:100%;" placeholder="是否首页">
            <el-option label="服务菜单" value="1"></el-option>
            <el-option label="店铺菜单" value="2"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="图片地址" prop="aname">
                    <el-input  v-model="editForm.imgUrl" auto-complete="off" /></el-input>
                </el-form-item> -->
        <el-form-item label="链接地址:" prop="serviceUrl">
          <el-input v-model="editForm.serviceUrl" auto-complete="off" /></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="editFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
      </div>
    </el-dialog>

    <!--新增界面-->
    <el-dialog title="新增" v-model="addFormVisible" :close-on-click-modal="false">
      <el-form :model="addForm" label-width="120px" :rules="addFormRules" ref="addForm">
        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="中文名称:" prop="serviceCname">
              <el-input v-model="addForm.serviceCname" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="英文名称:" prop="name">
              <el-input v-model="addForm.serviceEname" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="是否有效:" prop="isValidate">
              <el-select v-model="addForm.isValidate" class="otherWidth" placeholder="是否有效">
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="是否首页:" prop="isFirst">
              <el-select v-model="addForm.isFirst" class="otherWidth" placeholder="是否首页">
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="跳转方式:" prop="toType">
              <el-select v-model="addForm.toType" class="otherWidth" placeholder="跳转方式">
                <el-option label="内部跳转" value="0"></el-option>
                <el-option label="外部跳转" value="1"></el-option>
                <el-option label="电话号码" value="2"></el-option>
                <el-option label="产品跳转" value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="服务类型:" prop="serviceType">
              <el-select v-model="addForm.serviceType" class="otherWidth" placeholder="服务类型">
                <el-option label="理赔服务" value="理赔服务"></el-option>
                <el-option label="尊客会" value="尊客会"></el-option>
                <el-option label="在线客服" value="在线客服"></el-option>
                <el-option label="base" value="base"></el-option>
                <el-option label="店铺管理" value="店铺管理"></el-option>
                <el-option label="销售工具" value="销售工具"></el-option>
              </el-select>
              <!-- <el-button @click="moreType">更多</el-button> -->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="基本服务:" prop="baseService">
              <el-select v-model="addForm.baseService" class="otherWidth" placeholder="基本服务类型">
                <el-option label="保单查询" value="policy"></el-option>
                <el-option label="电子发票" value="invoice"></el-option>
                <el-option label="马上报案" value="fnol"></el-option>
                <el-option label="理赔查询" value="claim_query"></el-option>
                <el-option label="上传照片" value="claim_upload"></el-option>
                <el-option label="历史赔案" value="claim_history"></el-option>
                <el-option label="投保缴费" value="pay"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="20" :md="16" :lg="11">
            <el-form-item label="序号:" prop="serialNo">
              <el-input v-model="addForm.serialNo" auto-complete="off"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="图片地址" prop="name">
          <!--  <el-input v-model="editForm.introduceUrl"  auto-complete="off"></el-input> -->
          <el-upload class="upload-demo" :action="picURL" :on-success="addSuccessUrl" :on-remove="addRemoveUrl" :file-list="fileList1" :data="{parampath:'servicemenu'}" list-type="picture">
            <el-button size="small" type="primary">点击上传</el-button>
            <!-- <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div> -->
          </el-upload>
        </el-form-item>
        <el-form-item label="服务编码:" prop="serviceCode">
          <el-input v-model="addForm.serviceCode" auto-complete="off"></el-input>
        </el-form-item>
        <!-- <el-form-item label="图片地址" prop="aname">
                    <el-input  v-model="addForm.imgUrl" auto-complete="off" /></el-input>
                </el-form-item> -->
        <el-form-item label="链接地址:" prop="serviceUrl">
          <el-input v-model="addForm.serviceUrl" auto-complete="off" /></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="addFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
import commons from '../../common/js/common'

import util from '../../common/js/util'
import { mapState, mapActions } from 'vuex'
//import NProgress from 'nprogress'
import { getServiceListPage, removeService, batchRemoveUser, editService, addService, picURL } from '../../api/api';

export default {
  data() {
    return {
      filters: {
        serviceCname: '',
        isValidate: '',
        serviceType: '',
        toType: ''
      },
      picURL: picURL,
      Services: [],
      total: 0,
      page: 1,
      pageSize: 10,
      listLoading: false,
      exportTotal: 0,
      loading: '',
      sels: [],//列表选中列
      fileList2: [],
      fileList1: [],
      editFormVisible: false,//修改界面是否显示
      editLoading: false,
      editFormRules: {
        serviceCname: [
          { required: true, message: '请输入中文名称', trigger: 'blur' }
        ],
        isValidate: [
          { required: true, message: '请选择是否有效', trigger: 'blur' }
        ],
        isFirst: [
          { required: true, message: '请选择是否首页', trigger: 'blur' }
        ],
        toType: [
          { required: true, message: '请选择跳转状态', trigger: 'blur' }
        ],
        serviceType: [
          { required: true, message: '请选择服务类型', trigger: 'blur' }
        ],
        // baseService: [
        //   { required: true, message: '请选择基本服务', trigger: 'blur' }
        // ],
        serviceCode: [
          { required: true, message: '请输入服务编码', trigger: 'blur' }
        ],
        serviceUrl: [
          { required: true, message: '请输入链接地址', trigger: 'blur' }
        ],
        serialNo: [
          { required: true, message: '请输入序号', trigger: 'blur' }
        ]
      },
      //修改界面数据
      editForm: {
        serviceCname: '',
        serviceEname: '',
        imgUrl: '',
        isValidate: '',
        isFirst: '',
        toType: '',
        serviceType: '',
        serviceCode: '',
        serviceUrl: '',
        baseService: '',
        serialNo: ''
      },

      addFormVisible: false,//新增界面是否显示
      addLoading: false,
      addFormRules: {
        serviceCname: [
          { required: true, message: '请输入中文名称', trigger: 'blur' }
        ],
        isValidate: [
          { required: true, message: '请选择是否有效', trigger: 'blur' }
        ],
        isFirst: [
          { required: true, message: '请选择是否首页', trigger: 'blur' }
        ],
        toType: [
          { required: true, message: '请选择跳转状态', trigger: 'blur' }
        ],
        serviceType: [
          { required: true, message: '请选择服务类型', trigger: 'blur' }
        ],
        // baseService: [
        //   { required: true, message: '请选择基本服务', trigger: 'blur' }
        // ],
        serviceCode: [
          { required: true, message: '请输入服务编码', trigger: 'blur' }
        ],
        serviceUrl: [
          { required: true, message: '请输入链接地址', trigger: 'blur' }
        ],
        serialNo: [
          { required: true, message: '请输入序号', trigger: 'blur' }
        ]
      },
      //新增界面数据
      addForm: {
        serviceCname: '',
        serviceEname: '',
        imgUrl: '',
        isValidate: '',
        isFirst: '0',
        toType: '',
        serviceType: '',
        serviceCode: '',
        serviceUrl: '',
        baseService: '',
        serialNo: ''
      },

      queryBtnVisible: false,
      addBtnVisible: false,
      exportBtnVisible: false,
      updateBtnVisible: false,
      deleteBtnVisible: false,
      batchDeleteBtnVisible: false
    }
  },
  computed: mapState([
    'winWidth',
    'winHeight'
  ]),
  methods: {
    //险种编码转换
    formatisValidate: function (row, column) {
      return row.isValidate == '1' ? '是' : '否';
    },
    formatisFirst: function (row, column) {
      return row.isFirst == '1' ? '是' : '否';
    },
    formattoType: function (row, column) {
      return row.toType == '0' ? '内部跳转' : (row.toType == '1' ? '外部跳转' : (row.toType == '4' ? '产品跳转' : '电话号码'));
    },
    formatisService: function (row, column) {
      return row.serviceCode == '1' ? '服务菜单' : '店铺菜单';
    },

    moreType: function () {

    },
    // formatserviceType: function (row,column) {
    //   return row.serviceType == '1' ? '一' : '二';
    // },
    //上传图片
    addSuccessUrl(response, file, fileList) {
      this.addForm.imgUrl = commons.SuccessUrl(this.addForm.imgUrl, file);
    },
    addRemoveUrl(file, fileList) {
      this.addForm.imgUrl = commons.RemoveUrl(this.addForm.imgUrl, file);
    },
    editSuccessUrl(response, file, fileList) {
      this.editForm.imgUrl = commons.SuccessUrl(this.editForm.imgUrl, file);
    },
    editRemoveUrl(file, fileList) {
      this.editForm.imgUrl = commons.RemoveUrl(this.editForm.imgUrl, file);
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getServices(true);
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getServices(true);
    },
    //获取用户列表
    getServices(bool) {
      // let para = {
      //   pageSize: 10,
      //   pageNumber: this.page,
      //   productCname:'',
      //   riskCode:'',
      //   startDate:'',
      //   endDate:''
      // }
      let para = new FormData();
      para.append("pageSize", bool ? this.pageSize : this.exportTotal);
      para.append("pageNumber", bool ? this.page : 1);
      para.append("serviceCname", this.filters.serviceCname);
      para.append("isValidate", this.filters.isValidate);
      para.append("toType", this.filters.toType);
      para.append("serviceType", this.filters.serviceType);
      this.listLoading = bool;
      //NProgress.start();
      if (!bool) {
        this.loading = this.$loading({
          lock: true,
          text: '正在导出',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
      }
      getServiceListPage(para).then((res) => {
        this.total = res.data.result.totalElements;
        this.exportTotal = res.data.result.totalElements;
        this.lists = res.data.result.content;
        this.listLoading = false;
        if (!bool) {
          this.loading.close();
          this.export2Excel();
        }
        else {
          this.Services = res.data.result.content;
        }
        //NProgress.done();
      }).catch(() => {
        if (!bool) {
          this.$message({
            message: '导出异常',
            type: 'error'
          });
          this.loading.close();
        }

      });
    },
    //删除
    handleDel: function (index, row) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        //NProgress.start();
        let para = new FormData();
        para.append("ids", row.id);
        removeService(para).then((res) => {
          this.listLoading = false;
          //NProgress.done();
          this.$message({
            message: '删除成功',
            type: 'success'
          });
          this.getServices(true);
        });
      }).catch(() => {

      });
    },

    //table导出excel
    exportExcels: function () {
      this.getServices(false);
    },
    export2Excel: function () {
      require.ensure([], () => {
        const { export_json_to_excel } = require('../../vendor/Export2Excel');
        const tHeader = ['服务名称', '服务英文名称', '图片地址', '是否有效', '是否首页', '跳转方式', '服务类型', '链接地址'];
        const filterVal = ['serviceCname', 'serviceEname', 'imgUrl', 'isValidate', 'isFirst', 'toType', 'serviceType', 'serviceUrl'];
        const list = this.lists;
        for (var i in list) {
          list[i].isValidate = commons.IsValidate(list[i].isValidate);
          list[i].isFirst = commons.IsFirst(list[i].isFirst);
          list[i].toType = commons.ToType(list[i].toType);
        }
        const data = this.formatJson(filterVal, list);
        export_json_to_excel(tHeader, data, '服务菜单配置列表excel');
      })
    },
    formatJson: function (filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    },

    //显示修改界面
    handleEdit: function (index, row) {
      let _this = this;
      _this.editFormVisible = true;
      _this.fileList2 = [];
      _this.editForm = Object.assign({}, row);
      var URL1 = row.imgUrl.split(",");
      if (URL1.length > 0 && URL1[0] != "") {
        for (var i in URL1) {
          _this.fileList2.push({
            name: commons.interceptName(URL1[i]),
            url: URL1[i]
          });
        }
      }
      else {
        _this.fileList2 = [];
      }
      _this.editForm.imgUrl = URL1.join(',');
    },
    //显示新增界面
    handleAdd: function () {
      this.addFormVisible = true;
      this.addForm = {
        // id: '',
        serviceCname: '',
        serviceEname: '',
        imgUrl: '',
        isValidate: '',
        isFirst: '0',
        toType: '',
        serviceType: '',
        serviceCode: '',
        serviceUrl: '',
        baseService: ''
      };
      // let para = {
      //   id: parseInt(this.addForm.id),
      //   productCname: this.addForm.productCname,
      //   productEname: this.addForm.productEname,
      //   deadLine: this.addForm.deadLine,
      //   maxAge: parseInt(this.addForm.maxAge),
      //   minAge: parseInt(this.addForm.minAge),
      //   priPrice: parseFloat(this.addForm.priPrice),
      //   startDate: this.addForm.startDate,
      //   endDate: this.addForm.endDate
      // };
    },
    //修改
    editSubmit: function () {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.editLoading = true;
            //NProgress.start();
            let para = Object.assign({}, this.editForm);
            para.startDate = (!para.startDate || para.startDate == '') ? '' : util.formatDate.format(new Date(para.startDate), 'yyyy-MM-dd');
            para.endDate = (!para.endDate || para.endDate == '') ? '' : util.formatDate.format(new Date(para.endDate), 'yyyy-MM-dd');
            editService(para).then((res) => {
              this.editLoading = false;
              //NProgress.done();
              this.$message({
                message: '提交成功',
                type: 'success'
              });
              this.$refs['editForm'].resetFields();
              this.editFormVisible = false;
              this.getServices(true);
            }).catch(() => {
              this.$message({
                message: '数据异常',
                type: 'error'
              });
              this.editLoading = false;
            });
          });
        }
      });
    },
    //新增
    addSubmit: function () {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.addLoading = true;
            //NProgress.start();
            let para = Object.assign({}, this.addForm);
            para.startDate = (!para.startDate || para.startDate == '') ? '' : util.formatDate.format(new Date(para.startDate), 'yyyy-MM-dd');
            para.endDate = (!para.endDate || para.endDate == '') ? '' : util.formatDate.format(new Date(para.endDate), 'yyyy-MM-dd');
            addService(para).then((res) => {
              this.addLoading = false;
              //NProgress.done();
              this.$message({
                message: '提交成功',
                type: 'success'
              });
              this.$refs['addForm'].resetFields();
              this.addFormVisible = false;
              this.getServices(true);
            }).catch(() => {
              this.$message({
                message: '数据异常',
                type: 'error'
              });
              this.addLoading = false;
            });
          });
        }
      });
    },
    selsChange: function (sels) {
      this.sels = sels;
    },
    //批量删除
    batchRemove: function () {
      var ids = this.sels.map(item => item.id).toString();
      this.$confirm('确认删除选中记录吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        //NProgress.start();
        // let para = { ids: ids };
        let para = new FormData();
        para.append("ids", ids);
        removeService(para).then((res) => {
          this.listLoading = false;
          //NProgress.done();
          this.$message({
            message: '删除成功',
            type: 'success'
          });
          this.getServices(true);
        });
      }).catch(() => {

      });
    },

    btnShow: function () {
      let thisData = JSON.parse(sessionStorage.getItem('143'));
      let _this = this;
      $.each(thisData, function (i, j) {
        if (thisData[i] == "serviceMenuQuery") {
          _this.queryBtnVisible = true;
        }
        if (thisData[i] == "serviceMenuAdd") {
          _this.addBtnVisible = true;
        }
        if (thisData[i] == "serviceMenuExport") {
          _this.exportBtnVisible = true;
        }
        if (thisData[i] == "serviceMenuUpdate") {
          _this.updateBtnVisible = true;
        }
        if (thisData[i] == "serviceMenuRemove") {
          _this.deleteBtnVisible = true;
        }
        if (thisData[i] == "serviceMenuBatchRemove") {
          _this.batchDeleteBtnVisible = true;
        }
      });
    }
  },
  mounted() {
    this.getServices(true);
    this.btnShow();
  }
}

</script>

<style scoped>

</style>